package c.j.a.d.b.i.a;

import c.j.a.d.b.e.b;
import c.j.a.d.b.i.f;
import com.huawei.agconnect.exception.AGCServerException;
import com.ss.android.socialbase.downloader.g.e;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* compiled from: FakeDownloadHeadHttpConnection */
public class d implements f {
    public static final ArrayList<String> j;
    public final String a;
    public List<e> b;
    public Map<String, String> c = null;
    public int d;
    public long e;
    public final Object f = new Object();
    public boolean g;
    public boolean h;
    public f i;

    static {
        ArrayList arrayList = new ArrayList(6);
        j = arrayList;
        arrayList.add("Content-Length");
        arrayList.add("Content-Range");
        arrayList.add("Transfer-Encoding");
        arrayList.add("Accept-Ranges");
        arrayList.add("Etag");
        arrayList.add("Content-Disposition");
    }

    public d(String str, List<e> list, long j) {
        this.a = str;
        this.b = list;
    }

    public String a(String str) {
        Map map = this.c;
        if (map != null) {
            return (String) map.get(str);
        }
        f fVar = this.i;
        return fVar != null ? fVar.a(str) : null;
    }

    public int b() throws IOException {
        return this.d;
    }

    public void c() {
        f fVar = this.i;
        if (fVar != null) {
            fVar.c();
        }
    }

    public void e() throws Exception {
        if (this.c == null) {
            boolean z = true;
            try {
                this.h = true;
                this.i = b.d(this.a, this.b, 0, false, null);
                synchronized (this.f) {
                    if (this.i != null) {
                        HashMap hashMap = new HashMap();
                        this.c = hashMap;
                        f(this.i, hashMap);
                        this.d = this.i.b();
                        this.e = System.currentTimeMillis();
                        int i = this.d;
                        if (i < AGCServerException.OK || i >= 300) {
                            z = false;
                        }
                        this.g = z;
                    }
                    this.h = false;
                    this.f.notifyAll();
                }
            } catch (Throwable th) {
                synchronized (this.f) {
                    if (this.i != null) {
                        HashMap hashMap2 = new HashMap();
                        this.c = hashMap2;
                        f(this.i, hashMap2);
                        this.d = this.i.b();
                        this.e = System.currentTimeMillis();
                        int i2 = this.d;
                        if (i2 < AGCServerException.OK || i2 >= 300) {
                            z = false;
                        }
                        this.g = z;
                    }
                    this.h = false;
                    this.f.notifyAll();
                }
            }
        }
    }

    public final void f(f fVar, Map<String, String> map) {
        if (fVar != null) {
            Iterator it = j.iterator();
            while (it.hasNext()) {
                String str = (String) it.next();
                map.put(str, fVar.a(str));
            }
        }
    }

    public boolean g() {
        return System.currentTimeMillis() - this.e < b.d;
    }
}
